import { net } from 'electron'
/**
 * @description 去除前缀
 * @param data
 * @param prefix
 * @returns
 */
export const removePrefix = (data, prefix) => {
  return data.map((item) => {
    const newItem = {}
    for (const key in item) {
      if (key.startsWith(prefix)) {
        const newKey = key.slice(prefix.length)
        newItem[newKey] = item[key]
      } else {
        newItem[key] = item[key]
      }
    }
    return newItem
  })
}

export const getUTCDate = () => {
  // 获取当前 UTC 时间的 Date 对象
  const utcNow = new Date(
    Date.UTC(
      new Date().getUTCFullYear(),
      new Date().getUTCMonth(),
      new Date().getUTCDate(),
      new Date().getUTCHours(),
      new Date().getUTCMinutes(),
      new Date().getUTCSeconds(),
      new Date().getUTCMilliseconds()
    )
  )
  return utcNow
}

export const isOnline = () => {
  return net.online
}
